// 校验js文件
var relationCheck = {};//关联性校验全局字段
const validRules = {
     /*基本信息填报模块*/
    cx_checkMobilePhone(rule, value, callback){
        var myreg = /^(13[0-9]|14[1457]|15[0-3,5-9]|16[6]|17[0145678]|18[0-9]|19[89])\d{8}$/;
        var phoneNumbers = ['0000000', '1111111', '2222222', '3333333', '4444444', '5555555', '6666666', '7777777', '8888888', '9999999', '1234567', '7654321', ];
        if(value.trim() == ''){
            callback(new Error('请输入移动电话号码！'));
        }else if(!myreg.test(value)){
            callback(new Error('请输入有效的手机号码！'));
        }
        for (let i = 0; i < phoneNumbers.length; i++) {
            if (value.indexOf(phoneNumbers[i]) > 0) {
                callback(new Error('请输入有效的手机号码！'));
            }
        }
        callback()
    },
    //证件类型
    cx_idType(rule, value, callback){
        relationCheck['idType'] = value;
        callback()
    },
    //证件号码
    cx_checkIdCard(rule, value, callback) {
        var id_reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
        var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",
                32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",
                45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",
                64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
        if (value != '' && relationCheck['idType'] == 1) {
            if(value.length == 18){
                if(!id_reg.test(value)){
                    callback(new Error('身份证件出生日期或最后1位校验码填写有误!'));
                } else if(!city[value.substr(0,2)]){
                    callback(new Error('地址编码有误，请仔细检查号码前2位!'));
                } else {
                    callback()
                }
            }else {
                callback(new Error(`请填写18位有效身份证件号码!`))
            }
        }else {
            callback()
        }
    },
    //是否一般税收人
    cx_generalTaxpayer(rule, value, callback){
        relationCheck['generalTaxpayer'] = value;
        callback()
    },
    //税务登记号校验
    cx_registrationNumber(rule, value, callback){
       if(value.trim() == ''){
           callback()
       }
       if(relationCheck['generalTaxpayer'] == '是' && value.trim() == ''){
         callback(new Error(`税务登记号不能为空!`))
       }
       if(value.length != 15 && value.length != 18 && value.length != 20){
         callback(new Error(`税务登记号长度为15位或18位或20位!`))
       }else {
         callback()
       }
    },
    //税务登记号码校验
    cx_registrationContactNumber(rule, value, callback){
        var mobilephone = /^[\d+]+[\d-+]*$/;
        var mobile = value.trim();
        if(relationCheck['generalTaxpayer'] == '是' && mobile == ''){
            callback(new Error(`税务登记联系电话不能为空!`))
        }
        if(!mobile){
            callback()
        }
        if (mobilephone.test(mobile) && mobile) {
            if (mobile.length < 6) {
                callback(new Error('联系电话长度不能小于6位!'));
            } else {
                callback()
            }
        } else {
            callback(new Error('联系电话格式不正确!'));
        }

    },
    cx_taxBankName(rule, value, callback){
        if(relationCheck['generalTaxpayer'] == '是' && value == ''){
            callback(new Error(`税务开户银行名称不能为空!`))
        }else {
            callback()
        }
    },
    cx_taxBankAccount(rule, value, callback){
        if(relationCheck['generalTaxpayer'] == '是' && value == ''){
            callback(new Error(`税务开户银行帐号不能为空!`))
        }else {
            callback()
        }
    },
    cx_addInvoice(rule, value, callback){
        if(relationCheck['generalTaxpayer'] == '是' && value == ''){
            callback(new Error(`不能为空!`))
        }else {
            callback()
        }
    },
    cx_taxAddress(rule, value, callback){
        if(relationCheck['generalTaxpayer'] == '是' && value == ''){
            callback(new Error(`税务登记地址不能为空!`))
        }else {
            callback()
        }
    },
    cx_submitTaxAuditData(rule, value, callback){
        if(value != ""){
            relationCheck['submitTaxAuditData'] = new Date(value).getTime();
        }
        if(relationCheck['generalTaxpayer'] == '是' && value == ''){
            callback(new Error(`【提交税务审核日期】不能为空!`))
        }else {
            callback()
        }
    },
    cx_reviewStatus(rule, value, callback){
        relationCheck['reviewStatus'] = value;
        if(relationCheck['generalTaxpayer'] == '是' && value == ''){
            callback(new Error(`审核状态不能为空!`))
        }else {
            callback()
        }
    },
    cx_taxApprovalDate(rule, value, callback){
        let taxApprovalDate = new Date(value).getTime();
        if(relationCheck['reviewStatus'] == 1 && value == ''){
            callback(new Error(`【审核状态】为通过时,【税务审核通过日期】不能为空!`))
        }
        if(taxApprovalDate < relationCheck['submitTaxAuditData']){
            callback(new Error(`【税务审核通过日期】不能小于【提交税务审核日期】`))
        }else {
            callback()
        }
    },
    cx_phoneNumber(rule, value, callback){
        var mobilephone = /^[\d]*$/;
        var mobile = value.trim();
        if(mobile){
            if (mobile.length != 11 && !mobilephone.test(mobile)) {
                // callback(new Error('联系电话为以153、183、180、133、189、181、170、177开头的11位电信移动号码!'))
                callback(new Error('请输入正确的11位电信移动号码!'))
            } else {
                var HEAD_3 = mobile.substring(0, 3);
                if (HEAD_3 != 153 && HEAD_3 != 183 && HEAD_3 != 180 && HEAD_3 != 133 && HEAD_3 != 189 && HEAD_3 != 181 && HEAD_3 != 170 && HEAD_3 != 177) {
                    callback(new Error('请输入正确的11位电信移动号码!'))
                } else {
                    callback()
                }
            }
        }else {
            callback()
        }
    },
    // 取票方式关联邮箱校验
    cx_ticketsWay(rule, value, callback){
        relationCheck['ticketsWay'] = value;
        callback()
    },
    //邮寄地址校验
    cx_mailAddress(rule, value, callback){
        if(relationCheck['ticketsWay'] == '1' && value.trim() == ''){
            callback(new Error('取票方式选择【邮寄】时邮寄地址不能为空!'))
        }else {
            callback()
        }
    },
    //地址邮编校验
    cx_zipCode(rule, value, callback){
        if(relationCheck['ticketsWay'] == '1' && value.trim() == ''){
            callback(new Error('取票方式选择【邮寄】时邮编不能为空!'))
        }else {
            callback()
        }
    },

    /*修改基本信息模块*/

    // 改变证件类型
    cx_edit_idType(rule, value, callback){
        relationCheck['edit_idType'] = value;
        callback()
    },
    //证件号码校验
    cx_edit_idNumber(rule, value, callback){
        let reg =  /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
		let regs = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        let cerType = relationCheck['edit_idType']
        if(cerType == '1' || cerType == '2' || cerType == '41'){
            if(reg.test(value) == false || value.length != 18){
                callback(new Error('证件号码输入有误,请重新输入。'))
            }else{
                callback()
            }
        }else if(cerType == '14' || cerType == '3' || cerType == '4' || cerType == '42'){
            if(value.length < 4){
                callback(new Error('该类证件号码不能少于4位！'))
            }else{
                callback()
            }
        }else if(cerType == '50'){
            if(value.length < 15){
               callback(new Error('外国人永久居留身份证证件号不得少于15个字符！'))
            }else{
                callback()
            }
        }else if(cerType == '12'){
            if((value.length == 15 || value.length == 18) && regs.test(value) == true){
                callback()
            }else{
                callback(new Error('证件号码输入有误,请重新输入。'))
            }
        }else{
            callback()
        }
    },
    //经办人姓名校验
    cx_edit_certificationPersion(rule, value, callback){
        let isName =  /^[\u4e00-\u9fa5.·]*$/; 
        let regName = /^[\u4E00-\u9FA5]{2,10}$/;
        let cerType = relationCheck['edit_idType']
        if(cerType == '1' || cerType == '3' || cerType == '4' || cerType == '12' || cerType == '42' || cerType == '2' || cerType == '41' || cerType == '14'){
            if(''== value){
                callback(new Error('经办人姓名不能为空!'))
             }else{
                 if(value.length < 2){
                     callback(new Error('证件姓名不能少于2个汉字!'))
                }else{
                     if(regName.test(value)== false){
                        if(isName.test(value) == false){
                             callback(new Error('证件姓名不能包含除“.”和“·”以外的特殊字符!'))
                         }else{
                            callback()
                     }
                    }else{
                        callback()
                    }				   						
               }
             }
         }else if(cerType == '50'){
             if(''== value){
                callback(new Error('经办人姓名不能为空!'))
             }else if(value.length < 2){
                 callback(new Error('证件姓名不能少于2个汉字'))
            }else{
                callback()
            }
         }else{
            callback()
         }
    },
    //证件地址
    cx_edit_idAddress(rule, value, callback){
        let cerType = relationCheck['edit_idType']
        if(cerType == 1 || cerType == 2 || cerType == 12 || cerType == 41){
            if(value == ""){
                callback(new Error('证件地址不能为空'))
            }else{
               if(value.length <6){
                   callback(new Error('该类证件证件地址不能少于6个字符'))
               }else{
                callback()
               }
             }		   		
          }else{
            callback()
        }	
    }

}
export default validRules;
